package com.set;

import java.util.ArrayList;

/**
 * 性能测试：对比基于链表和二分搜索树的集合的性能
 */
public class PerformanceTest {

    private static double testPerformance(Set<String> set, String fileName) {
        long startTime = System.nanoTime();
        System.out.println(fileName);
        ArrayList<String> words = new ArrayList<>();
        if(FileOperation.readFile(fileName, words)) {
            System.out.println("Total words: " + words.size());
            for (String word : words) {
                set.add(word);
            }
            System.out.println("Total different words: " + set.getSize());
        }
        long endTime = System.nanoTime();
        return (endTime - startTime)/1000000000.0;
    }

    public static void main(String[] args) {
        String fileName =  "E:\\WorkSpace\\LearningDemoWorkSpace\\data-structure\\src\\pride-and-prejudice.txt";
        BSTSet<String> bstSet = new BSTSet<>();
        double time1 = testPerformance(bstSet, fileName);
        System.out.println("BST set: " + time1 + " s");

        System.out.println();

        LinkedListSet<String> LinkedListSet = new LinkedListSet<>();
        double time2 = testPerformance(LinkedListSet, fileName);
        System.out.println("Linked list set: " + time2 + " s");

        System.out.println();
        AVLSet<String> avlSet = new AVLSet<>();
        double time3 = testPerformance(avlSet, fileName);
        System.out.println("AVLSet set: " + time3 + " s");

    }
}
